package com.chengfei.service;

import com.chengfei.rabbitmq.RabbitMQConfiguration;
import lombok.extern.log4j.Log4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author chengfei cheng.fei@chinaott.onaliyun.com
 **/
@Service
@Log4j
public class Sender {
    @Autowired
    private AmqpTemplate amqpTemplate;
    public void send(String message){
        log.info("程飞 发送消息");
        amqpTemplate.convertAndSend(RabbitMQConfiguration.QUEUE_NAME,message);
    }
    public void sendTopicMessage(String message){
        log.info("send topic");
        amqpTemplate.convertAndSend(RabbitMQConfiguration.TOPIC_EXCHANGE,RabbitMQConfiguration.TOPIC_ROUTING_KEY1,message+"1");
        amqpTemplate.convertAndSend(RabbitMQConfiguration.TOPIC_EXCHANGE,RabbitMQConfiguration.TOPIC_ROUTING_KEY2,message+"2");

    }

    public void sendFanoutMessage(String message){
        log.info("sendFanoutMessage");
        amqpTemplate.convertAndSend(RabbitMQConfiguration.FANOUT_EXCHANGE,message);

    }
}
